//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <ddk.h>

EXTERN_C ECode C_Sleep(uint_t uTicks)
{
    DzSleep(uTicks, NULL);
    return 0;
}

EXTERN_C void C_Delay(uint_t uMicroseconds)
{
    DzDelay(uMicroseconds);
}

EXTERN_C void M_Delay(uint_t uMillisecond)
{
    DzDelay(uMillisecond * 1000);
}

/******************************************************************************
* Name: to_DWORD - Convert to 32-bit portable data
*
* Description
*       Convert a 32 bit intel item to a portable 32 bit data.
*
* Entries:
*       UTINY *from     Source buffer data
*
* Returns:
*       32-bit data
*
******************************************************************************/
EXTERN_C UInt32 to_DWORD(UInt8 *from) /*__fn__*/
{
    UInt32 res;
#if (BIG_ENDIAN)
    UInt32 t;
    t = ((UInt32) *(from + 3)) & 0x00FF;
    res = (t << 24);
    t = ((UInt32) *(from + 2)) & 0x00FF;
    res |= (t << 16);
    t = ((UInt32) *(from + 1)) & 0x00FF;
    res |= (t << 8);
    t = ((UInt32) *from) & 0x00FF;
    res |= t;

#else
    res = ((UInt32) *((UInt32 *)from));
#endif
    return (res);
}

/******************************************************************************
* Name: to_WORD - Covert to a portable 16-bit data
*
* Description
*       Convert a 16 bit intel item to a portable 16 bit.
*
* Entries:
*       UTINY *from     Source buffer data
*
* Returns:
*        16-bit data
*
******************************************************************************/
EXTERN_C UInt16 to_WORD(UInt8 *from) /*__fn__*/
{
    UInt16 nres;
#if (BIG_ENDIAN)
    UInt16 t;
    t = (UInt16) (((UInt16) *(from + 1)) & 0x00FF);
    nres = (UInt16) (t << 8);
    t = (UInt16) (((UInt16) *from) & 0x00FF);
    nres |= t;

#else
    nres = ((UInt16) *((UInt16 *)from));
#endif
    return (nres);
}
